package com.budwk.app.sqfw.controllers.admin.customservice;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.budwk.app.sqfw.services.SqfwFormSummaryService;
import com.budwk.app.sqfw.services.common.SqfwCustomForAdminCommonService;
import com.budwk.app.sqfw.vo.SqfwCustomForAdminCommonVO;
import com.budwk.app.sqfwDoc.bo.ExcelCreateConfig;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.List;

/**
 * @program: dfxy-community-dev
 * @description: 白云区儿童探访记录（后台管理）
 * @author: LJT
 * @create: 2024-04-28 15:08
 **/
@IocBean
@At("/platform/sqfw/BaiYunQuChildVisit")
@ApiDefinition(tag = "白云区儿童探访记录（后台管理）")
@Slf4j
public class BaiYunQuChildVisitForAdminController {
    @Inject(value = "BaiYunQuChildVisitForAdminService")
    private SqfwCustomForAdminCommonService sqfwCustomForAdminCommonService;

    @Inject
    private SqfwFormSummaryService sqfwFormSummaryService;

    @At("/get/{id}")
    @Ok("json")
    @GET
    @ApiOperation(name = "获取详情")
    @ApiResponses
    @SLog(tag = "获取详情", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> detail(@Param("id") String id) {
        return Result.data(sqfwFormSummaryService.fetch(id));
    }

    @At("/delete")
    @Ok("json")
    @DELETE
    @ApiOperation(name = "删除表数据")
    @SLog(tag = "删除表数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> delete(@Param("id") String id) {
        return Result.data(sqfwCustomForAdminCommonService.delete(id));
    }

    @At("/batchDelete")
    @Ok("json")
    @DELETE
    @ApiOperation(name = "批量删除表数据")
    @SLog(tag = "批量删除表数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> batchDelete(@Param("ids") List<String> ids) {
        return Result.data(sqfwCustomForAdminCommonService.batchDelete(ids));
    }

    /**
     * 列表查询
     */
    @At()
    @Ok("json")
    @POST
    @ApiOperation(name = "列表查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "create_date", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @ApiResponses(
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @SLog(tag = "公共列表查询（后台管理系统）", value = "${args[0]}}")
    @SaCheckLogin
    public Result<?> list(@Param("..") SqfwCustomForAdminCommonVO bean) {
        return Result.data(sqfwCustomForAdminCommonService.list(bean));
    }

    /**
     * 获取下载文件列表及数据检查
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "获取下载文件列表及数据检查")
    @ApiResponses(
            implementation = SqfwCustomForAdminCommonVO.class
    )
    @SLog(tag = "获取下载文件列表及数据检查", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> checkDataInfoList(@Param("..") SqfwCustomForAdminCommonVO sqfwFormSummaryForAdminVO) {
        return Result.data(sqfwCustomForAdminCommonService.checkDataInfoList(sqfwFormSummaryForAdminVO));
    }

    /**
     * excel下载
     *
     * @param sqfwFormSummaryForAdminVO
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "Excel文件下载")
    @SLog(tag = "Excel文件下载", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> downloadExcel(@Param("excelConfigList") List<ExcelCreateConfig> excelConfigList, @Param("..") SqfwCustomForAdminCommonVO sqfwFormSummaryForAdminVO) {
        return Result.data(sqfwCustomForAdminCommonService.downloadExcel(excelConfigList, sqfwFormSummaryForAdminVO));
    }

    /**
     * pdf下载
     *
     * @param sqfwFormSummaryForAdminVO
     * @return
     */
    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "pdf文件下载")
    @SLog(tag = "pdf文件下载", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> downloadPdf(@Param("excelConfigList") List<ExcelCreateConfig> excelConfigList, @Param("..") SqfwCustomForAdminCommonVO sqfwFormSummaryForAdminVO) {
        return Result.data(sqfwCustomForAdminCommonService.downloadPdf(excelConfigList, sqfwFormSummaryForAdminVO));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "重新生成PDF")
    @SaCheckLogin
    public Result<?> reGeneratePDF(@Param("sqfwFlowId") String sqfwFlowId) {
        sqfwCustomForAdminCommonService.reGeneratePdf(sqfwFlowId);
        return Result.success();
    }
}
